import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns

data1 = pd.read_csv("california_housing_s.csv")
data1 = data1.dropna(how='any')      #利用dropna删除空白值所在行，any为删除存在空白值行
# print(data1)
print(data1.keys())
# describe = data1.describe()
# print(describe)
# describe.to_excel('statistic.xlsx',sheet_name='statistic')
# data1.to_excel('home.xlsx',sheet_name='home')

latitude = data1['housing_median_age']
median_house_value = data1['median_house_value']
latitude = latitude.values                   #将dataframe格式数据转化为array格式
median_house_value = median_house_value.values
print(latitude)
# plt.scatter(latitude)
# plt.scatter(x=latitude,y=median_house_value)
plt.show()
r_matrix = data1.corr()
# print(r_matrix)
fig, ax = plt.subplots(figsize=(10, 10))  # 创建一个新的图形和坐标轴，设置图形大小为10x10 
sns.heatmap(r_matrix, annot=True, cmap='coolwarm', linewidths=.5, ax=ax)  # 绘制相关性矩阵的热图  

plt.show()  # 显示图形